package junior.db.dao.query;

import junior.db.dao.base.FilterMapperProvider;
import junior.db.dao.mybatis.type.ResultType;

import java.util.Map;

/**
 * @author wubo
 * @date 2024/8/30 15:09
 */
public class QueryMapperProvider extends FilterMapperProvider {
    
    public String get(AbstractQuery query) {
        query.beforeExecuteNode();
        return doQuery(query, "");
    }
    
    public String count(AbstractQuery query) {
        if (!query.hasAnySelects()) {
            query.selectExpression("count(*)", null);
        }
        query.beforeExecuteNode();
        return doQuery(query, "");
    }
    
    public String getForObject(Map<String, Object> param) {
        AbstractQuery query = (AbstractQuery) param.get("query");
        ResultType<?> resultType = (ResultType<?>) param.get("resultType");
        query.beforeExecuteNode();
        query.setResultType(resultType);
        return doQuery(query, "query");
    }
}
